package com.mz.ozy.mvp.presenter;

import android.app.Activity;
import android.content.Context;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.OrderBean;
import com.mz.ozy.constants.Constants;
import com.mz.ozy.mvp.view.ExchangeOrderContract;
import com.mz.ozy.mvp.view.FirmOrderContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.net.RetrofitUtils;
import com.mz.ozy.utils.JsonUtils;
import com.mz.ozy.utils.MD5Util;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import okhttp3.ResponseBody;

/**
 * Created by Administrator on 2018/12/7.
 */

public class ExchangeOrderPresenter extends BasePresenterImpl<ExchangeOrderContract.View> implements ExchangeOrderContract.Presenter {

    @Override
    public void detailSubmit(Activity activity, String id, String gid, String aid, String freightId, String remark, String pwd, String cardid) {
        Map<String, String> maps = new HashMap<>();
        maps.put("productid", id);
        maps.put("attribute_id", gid);
        maps.put("addressId", aid);
        maps.put("freightId", freightId);
        maps.put("remark", remark);
        maps.put("payPwd", MD5Util.getMD5String(pwd));
        maps.put("cardid", cardid);
        RetrofitUtils.getApiService(activity).post(Constants.TransCode.TransCode10081, JsonUtils.requestJsonDate(maps), Constants.tokenId)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<OrderBean>(mView, true) {

                    @Override
                    public void onSuccesss(OrderBean orderBean) {
                        mView.onSubmitSuccess(orderBean);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        mView.onSubmitError("");
                    }
                });
    }
}
